package com.ulife.permission.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ulife.permission.dao.UserDao;
import com.ulife.permission.dao.dataobject.UserDO;

public class UserDaoImpl extends SqlMapClientDaoSupport implements UserDao {

	public UserDO getUserByNameAndPassword(String userName, String password) throws SQLException {
		UserDO user = new UserDO();

        user.setUserName(userName);
        user.setPassword(password);

        return (UserDO) getSqlMapClient().queryForObject("User.getUserByNameAndPassword", user);
	}

	public UserDO getUserById(long userId) throws SQLException {
		return (UserDO)getSqlMapClient().queryForObject("User.getUserById",userId);
	}

	public int addUser(UserDO user) throws SQLException {
		return getSqlMapClient().update("User.insertUser",user);
	}

	@SuppressWarnings("unchecked")
	public List<UserDO> getAllUser() throws SQLException {
		return getSqlMapClient().queryForList("User.selectAllUsers");
	}

	public int delUser(long userId) throws SQLException {
		return getSqlMapClient().update("User.delUser", userId);
	}

	public int updateUser(UserDO user) throws SQLException {
		return getSqlMapClient().update("User.updateAllInfo", user);
	}

	@SuppressWarnings("unchecked")
	public List<UserDO> getAllAvailableUsers() throws SQLException {
		return getSqlMapClient().queryForList("User.getAllAvailableUsers");
	}

}
